package henu.graduation_design.onlineshop;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;

import henu.graduation_design.adapter.AppraiseAdapter;
import henu.graduation_design.tool.AnalyseProductAppraiseJson;
import henu.graduation_design.util.JsonLoader;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

public class AppraiseActivity extends Activity {

	ListView appraiseListView;
	ImageView backImageView,loadImageView;
	String productID;
//	Animation rotateAnimation;

	private JsonLoader jsonLoader = new JsonLoader();
	List<HashMap<String, Object>> list;
	AppraiseAdapter adapter;

	private void loadAppraiseJson(final String url) {
		jsonLoader.getJsonArray(url, new JsonLoader.JsonArrayCallback() {
			public void jsonLoaded(JSONArray jsonArray) {
				list.clear();
				AnalyseProductAppraiseJson analyse = new AnalyseProductAppraiseJson(
						jsonArray);
				try {
					list = analyse.getList();
				} catch (JSONException e) {
					Toast.makeText(getApplicationContext(),
							"解析category的json数据发生异常", Toast.LENGTH_LONG).show();
				}
				//rotateAnimation.cancel();
				adapter = new AppraiseAdapter(AppraiseActivity.this, list);
				appraiseListView.setAdapter(adapter);
			}
		});
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_appraise);
		appraiseListView = (ListView) findViewById(R.id.appraise_listview);
		backImageView = (ImageView) findViewById(R.id.page_back);
		list = new ArrayList<HashMap<String, Object>>();
		Intent intent = getIntent();// 获得传过来的Intent。
		productID = intent.getStringExtra("ID");// 根据键name取出值。
		try {
			String urlString = getString(R.string.url_product_appraise)
					+ "?id=" + productID + "&tag=0";
			loadAppraiseJson(urlString);
		} catch (Exception e) {
			e.printStackTrace();
		}
		backImageView.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
	}

}
